<%@ page language="java" isELIgnored="false" import="java.util.*" pageEncoding="UTF-8" contentType="text/html; charset=UTF-8"%>
<%@ taglib prefix="s" uri="/struts-tags" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><s:text name="monitor.modifyTitle"/></title>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/show.js"></script>
<link rel="stylesheet" href="http://qunarzz.com/home/prd/styles/geilivible/release/home-2013012823365302.css">
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/jquery-1.6.4.min.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<script src="<%=request.getContextPath()%>/fare/js/ligerUI/js/core/base.js" type="text/javascript"></script>
<link href="<%=request.getContextPath() %>/fare/lib/ligerUI/skins/Aqua/css/ligerui-all.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath() %>/FusionCharts/FusionCharts.js"></script>
<link href="<%=request.getContextPath() %>/fare/css/base.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/common.js"></script>
<link rev="stylesheet" media="all" href="<%=request.getContextPath() %>/fare/css/form_style.css" type="text/css" rel="stylesheet">
<script type="text/javascript" src="<%=request.getContextPath()%>/fare/lib/ligerUI/js/plugins/ligerCheckBox.js"></script>
 <script type="text/javascript" src="<%=request.getContextPath()%>/fare/js/json2.js"></script>
 <link rel="stylesheet" type="text/css" href="<%=request.getContextPath()%>/fare/fdc/style.css" />
 <script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
<script	src="<%=request.getContextPath()%>/fare/lib/jquery/jquery.form.js"	type="text/javascript"></script>
<script type="text/javascript" src="<%=request.getContextPath() %>/fare/lib/ligerUI/js/ligerui.min.js"></script>
 <script type="text/javascript" src="<%=request.getContextPath() %>/fare/js/datePicker/WdatePicker.js"></script>
<script type="text/javascript" src="<%=request.getContextPath()%>/jsFile/multiblepicker.js"></script>
<link href="<%=request.getContextPath()%>/fare/js/cityquery/cityquery.css" rel="stylesheet" type="text/css" />
<script src="<%=request.getContextPath()%>/fare/js/cityquery/citylist.js" type="text/javascript"></script>
<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
<!-- 圆角文本框 -->
<link href="<%=request.getContextPath() %>/fare/css/htc/htc.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
 
$(document).ready(function(){
	var alerFlighDate=document.getElementById("monitor.settingAddHasSel").value;
		//定义一个全局变量
		window.CHENKED_FLIGHTS=new Array();
		window.CHECKED_STR=alerFlighDate;
	//	var obj=window.dialogArguments;//读取来自父窗口的数据
		 var careLines=$("#flightNumber").val();
		 var hbaseKeys=$("#companyCode").val();
		 var getALLshow=new Array();
		 var cls=careLines.split("/");
		 var hks=hbaseKeys.split("/");
		 for(var i=0;i<cls.length;i++){
			var  getALLshows=cls[i]+"/"+hks[i];
			getALLshow[i]=getALLshows;
		 }
		 CHENKED_FLIGHTS=getALLshow;
		flushCheckedFlights();
	
	}); 

function checkForm(){
	var alerFlighDate=document.getElementById("share.alertSelectFlighDate").value;
	var alertLocalSel=document.getElementById("share.showDifferent2").value;
	var alertSetF=document.getElementById("monitor.settingModifyF").value;
	var queryDates=document.getElementById("queryDate").value;
	var departcitys=document.getElementById("departcitys").value;
	var arrivalcitys=document.getElementById("arrivalcitys").value;
	var flag=true;
	if(queryDates=='' || queryDates == null ){
		flag=false;
		alert(alerFlighDate);
		return;
	}
	if (departcitys == '中文/拼音'|| arrivalcitys == '中文/拼音' || departcitys=='' || arrivalcitys=='') {
		flag = false;
		alert(alertLocalSel);
		return;
	}
	if(departcitys == arrivalcitys){
		flag = false;
		alert(alertLocalSel);
	}
	if(CHENKED_FLIGHTS.length==0){
		flag=false;
		var b=confirm(alertSetF);
		/* if(b==true){
			window.close();
		} */
	}
	return flag;
}

function changeAir(){
	var carrierKey=$("#airCompany").val();
	if(carrierKey==undefined || carrierKey==""){$("#flightnos option").remove();return ;}
	//获取航空公司的航线下的航班
		var fromCityCode=$("#depCityCode").val();
	var toCityCode=$("#arrCityCode").val();
	$.ajax({
		url:"<%=request.getContextPath()%>/airCompanyTrendContrastFlightAction!getFlightNo.action",
		data:{
			companyCarrierKey:carrierKey,
			fromCityCode:fromCityCode,
			toCityCode:toCityCode
		},
		type:'post',
		dataType:'json',
		cache : false, 
	    async : false,
	    beforeSend:function(){},
	    success:function(data){
	    	displayFlight(data);
	    },
	    error:function(){},
	    complete:function(){}
	});
}
//显示航班号
function displayFlight(data){
	//清除之前的航班
	$("#flightnos option").remove();
	if(data && data.length>0){
		for(var i=0;i<data.length;i++){
			if(isExistFlight(data[i].flightNo)==true){
				$("#flightnos").append("<option value='"+data[i].flightNo+"/"+data[i].companyCode+"'>"+data[i].flightNo+CHECKED_STR+"</option>");
			}else{
				$("#flightnos").append("<option value='"+data[i].flightNo+"/"+data[i].companyCode+"'>"+data[i].flightNo+"</option>");
			}
			
		}
	}
}
//是否存在航班号
function isExistFlight(f){
	var str=CHENKED_FLIGHTS.join("|");
	return str.indexOf(f)==-1?false:true;
}

//添加或删除被选择的航班
function addOrRemoveChioce(e){
	var alertSelectFli=document.getElementById("monitor.settingAddSeled").value;
	if(CHENKED_FLIGHTS.length < 5){
	var str=CHENKED_FLIGHTS.join("|");
	var op=$(e).find("option:selected");
	if(str.indexOf($(e).val())==-1){//不存在该航班
		CHENKED_FLIGHTS.unshift($(e).val());//放入
		$(op).text($(op).text()+CHECKED_STR);
	}else{//存在
		str=str.replace($(e).val(),"");
		var strs=str.split("|");
		CHENKED_FLIGHTS=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_FLIGHTS.push(strs[i]);
			}
		};
		$(op).text($(op).text().replace(CHECKED_STR,""));
	}
	flushCheckedFlights();
	//flushCheckedFlights2();
	}else{
		alert(alertSelectFli);
	}
	}
//刷新已经选择的航班
function flushCheckedFlights(){
	
	var table=$("#airLine");
	$(table).empty();
	var rowSize=5;//一行容纳多少个航班，动态的生成表格
	for(var i=1;i<=CHENKED_FLIGHTS.length;i++){
		if(i%rowSize==1){
			table.append("<tr></tr>");
		}
		$("tr:last",table).append("<td style='padding:5px 5px 5px 0px;border-bottom:0px;'>"
		+"<input type='checkbox' name='airLine' value='"+CHENKED_FLIGHTS[i-1]+"' checked='checked'  onclick='changeChecked(this)'/>&nbsp&nbsp"+CHENKED_FLIGHTS[i-1]
		+"</td>");
	}
}
//改变选项
function changeChecked(e){
	if($(e).attr("checked")!=true){//不选则删除他，同时需要改变select的显示方式还有全局变量
		var str=CHENKED_FLIGHTS.join("|");
		str=str.replace($(e).val(),"");
		var strs=str.split("|");
		CHENKED_FLIGHTS=[];
		for(var i=0;i<strs.length;i++){
			if(strs[i]!=null && $.trim(strs[i])!="" && strs[i]!="|"){
				CHENKED_FLIGHTS.push(strs[i]);
			}
		};
		flushCheckedFlights();
		$("#flightnos option").each(function(){
			if($(this).val()==$(e).val()){
				$(this).text($(this).val());
				return;
			}
		});
	}
}
//清除所有选项
function clearAll(){
	CHENKED_FLIGHTS=[];
	flushCheckedFlights();
//flushCheckedFlights2();
	$("#flightnos option").each(function(){
			$(this).text($(this).val());
	});
}
function modifys(){	
	var failureAlert=document.getElementById("share.fail").value;
	var alertModify=document.getElementById("share.sureModify").value;
	if(checkForm() ){
	if(	confirm(alertModify)){
	   $("#lineEditForm").ajaxSubmit({
		   url:"<%=request.getContextPath()%>/freightMonitorSettingsAction!modifys.action",
	    	
	    	type:"POST",
	    	async:false,
	    	cache : false, 
	   //	dataType:'json',
	   // 	contentType: "application/x-www-form-urlencoded; charset=utf-8", 
	    	 beforeSend:function(){	 },
	    	success:function(data){
	    		closeCheckedWindow();
	    	},
	    	 error:function(){
	    		 alert(failureAlert);
	    	 },
	 	    complete:function(){}
	    });
		}
	}
}

function sureConfig(){
	var alerFlighSel=document.getElementById("monitor.settingAddSel").value;
	if(CHENKED_FLIGHTS.length==0){
		var b=confirm(alerFlighSel);
		if(b==true){
			closeCheckedWindow();
		}
	}else{
		closeCheckedWindow();
	}
}
//关闭这个窗口
function closeCheckedWindow(){
	var successAlert=document.getElementById("share.success").value;
	alert(successAlert);
	var pWin = window.dialogArguments.pWin;//父窗口
	window.close();
	pWin.showDataAgain();
	
	
}


</script>
</head>

<body>
	<div class="form_body">
		<div class="main_max">
			<div class="high_10"></div>
			<div class="form_table_tltle"><s:text name="monitor.settingModifyPage"/></div>
			<form method="post" id="lineEditForm"	action="">
			
				<!-- internationalization  -->
				<input type="hidden" id="share.sureModify" value="<s:text name="share.sureModify"/>" />
				<input type="hidden" id="share.alertSelectFlighDate" value="<s:text name="share.alertSelectFlighDate"/>" />
				<input type="hidden" id="share.fail" value="<s:text name="share.fail"/>" />
				<input type="hidden" id="share.success" value="<s:text name="share.success"/>" />
				<input type="hidden" id="share.showDifferent2" value="<s:text name="share.showDifferent2"/>" />
				<input type="hidden" id="monitor.settingAddSel" value="<s:text name="monitor.settingAddSel"/>" />
				<input type="hidden" id="monitor.settingAddHasSel" value="<s:text name="monitor.settingAddHasSel"/>" />
				<input type="hidden" id="monitor.settingAddSeled" value="<s:text name="monitor.settingAddSeled"/>" />
				<input type="hidden" id="monitor.settingModifyAlertFD" value="<s:text name="monitor.settingModifyAlertFD"/>" />
				<input type="hidden" id="monitor.settingModifyAlertFL" value="<s:text name="monitor.settingModifyAlertFL"/>" />
				<input type="hidden" id="monitor.settingModifyF" value="<s:text name="monitor.settingModifyF"/>" />
			
				<input type="hidden" name="fromCityName" id="fromCityName" >
				<input type="hidden" name="toCityName" id="toCityName" >
				<input type="hidden" name="id" id="id" value="${volists.id }">
				<input type="hidden" name="currentUser" id="currentUser" value="${volists.currentUser }">
				<input type="hidden" name="result" id="result" value=""/>
				<input type="hidden" name="fromCode" id="fromCode" value="${volists.fromCode }">
				<input type="hidden" name="toCode" id="toCode" value="${volists.toCode }">
				<input type="hidden" name="areaCode" id="areaCode" value="${volists.areaCode }">
				<input type="hidden" name="hbaseKey" id="hbaseKey" value="${volists.hbaseKey }">
				<input type="hidden" name="companyCode" id="companyCode" value="${volists.companyCode }">
				<input type="hidden" name="flightNumber" id="flightNumber" value="${volists.flightNumber }">
				<table width="0" border="0" cellpadding="0" cellspacing="0" class="form_table">
					<tr>
						<td class="left" ><s:text name="share.flightDate"/>：</td>
						<td><input name="queryDate" type="text"	id="queryDate" style="width: 100px"    
						value="${volists.departDateString}" readonly="readonly"/>
						<span style="color: #ff0000">* <s:text name="monitor.settingModifyAlertFD"/></span></td>
									
					</tr>
					<tr>
						<td class="left" ><s:text name="share.flightLine"/> ：</td>
						<td><input type="text" name="fromCity" id="departcitys" value="${volists.fromCity }" readonly="readonly" /> 
						<s:text name ="share.to"/><input type="text"	name="toCity" id="arrivalcitys"  value="${volists.toCity}" readonly="readonly" />
						<span style="color: #ff0000">*  <s:text name="monitor.settingModifyAlertFL"/></span></td>
					</tr>
					<tr>
						<td class="left"><s:text name="share.airlineCompany"/>: </td>
						<td> 
							<select name="airCompany" id="airCompany" onchange="javascript:changeAir();" style="width:200px;padding:0px;">
							 	    <option value="">-- <s:text name="share.select"/> --</option>
  	                           <c:forEach var="item" items="${crawlCompanys}">
							        <option value="${item.carrierKey}">${item.name}</option>
						       </c:forEach>      
                            </select>
                        </td>
					</tr>
					<tr>
						<td class="left"><s:text name="share.flighNumber"/>:</td>
						<td>
							<select multiple="multiple" id="flightnos" name="flightnos" 
								style="height:200px;width:200px;" ondblclick="addOrRemoveChioce(this)" >
							</select>
							<!--  
							<img style="cursor: pointer;"
								src="<%=request.getContextPath() %>/fare/images/modify.png"
								name="querybutton" id="querybutton" onclick="addChioce()"/>
							-->
							<s:text name="monitor.settingClickS"/>
						</td>
					</tr>	
					<tr>
					 	<td class="left">
							<s:text name="monitor.settingSelectFlighs"/>:
						</td>
						<td>
							<!--  
							<input type="text" id="chiocevalue222" name="chiocevalue222" value="" style="width:350px;" readonly="readonly"/>
							-->
							<table id="airLine"></table>

						</td>
					 </tr>
					 <tr>
						<td class="right" colspan="2" style="padding-top:10px;padding-left:150px;">
							<img
							src="<%=request.getContextPath() %>/<s:text name ='monitor.updateBut'/>"
							name="querybutton" id="querybutton" onclick="javascript:modifys();" />
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<img
							src="<%=request.getContextPath() %>/<s:text name ='monitor.emptyBut'/>"
							name="cancelbutton" id="cancelbutton"
							onclick="javascript:clearAll();" /> 
							<%-- <input type="button" onclick="javascript:modifys();" value="" 
							class="<s:i18n name='forms'><s:text name='forms.btn04'></s:text></s:i18n>" id="querybutton"/>
							&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
							<input type="button" onclick="javascript:clearAll();" value="" 
							class="<s:i18n name='forms'><s:text name='forms.btn02'></s:text></s:i18n>" id="cancelbutton"/> --%>
						</td>
					 </tr>
		</table>
	</form>	
	<script type='text/javascript' src='<%=request.getContextPath()%>/fare/js/cityquery/querycity.js'></script>
</body>
</html>
